package com.handpay.zztong.hp.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.handpay.framework.utils.CommonUtils;
import com.handpay.framework.utils.DateUtils;
import com.handpay.zztong.hp.R;
import com.handpay.zztong.hp.bean.WithdrawRecordsBill;

public class WithDrawRecordsAdapter extends BaseAdapter
{
	private List<WithdrawRecordsBill>  withDrawBills;
	private LayoutInflater	inflater;
	
	public WithDrawRecordsAdapter(Context activity,List<WithdrawRecordsBill>  Bills){
	 
		this.withDrawBills = Bills;
		inflater = LayoutInflater.from(activity);
	}

	@Override
	public int getCount()
	{
		return this.withDrawBills.size();
	}

	@Override
	public Object getItem(int position)
	{
		return this.withDrawBills.get(position);
	}

	@Override
	public long getItemId(int position)
	{
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		ZuJian zuJian = null;
		if(convertView == null)
		{
			zuJian = new ZuJian();
			convertView = inflater.inflate(R.layout.withdrawrecords, null);
			zuJian.withdrawapplytime = (TextView)convertView.findViewById(R.id.withdrawtimetv);
			zuJian.withdrawstatus = (TextView)convertView.findViewById(R.id.withdrawstatus);
			zuJian.ll_applyWithdrawAmount = (LinearLayout)convertView.findViewById(R.id.applyWithdrawAmountll);
			zuJian.applyWithdrawAmount = (TextView)convertView.findViewById(R.id.applyWithdrawAmount);
			zuJian.ll_actualWithdrawAmount = (LinearLayout)convertView.findViewById(R.id.actualWithdrawAmountll);
			zuJian.actualWithdrawAmount = (TextView)convertView.findViewById(R.id.actualWithdrawAmount);
			convertView.setTag(zuJian);
		}else {
			zuJian = (ZuJian)convertView.getTag();
		}
		WithdrawRecordsBill bills = withDrawBills.get(position);
		zuJian.withdrawapplytime.setText(DateUtils.formatDateToString(
				DateUtils.formatStringToDate(bills.getWithDrawApplyTime(), "yyyyMMddHHmmss"), "yyyyMMdd HH:mm:ss"));
        zuJian.withdrawstatus.setText(bills.getWithDrawDes());

        int wdStatus = bills.getWithDrawstatus();
        //提现申请失败、提现失败，字体为红色。否则为黑色
        if(WithdrawRecordsBill.STATUS_FAILED == wdStatus || WithdrawRecordsBill.STATUS_WD_FAIL == wdStatus) {
            zuJian.withdrawstatus.setTextColor(Color.RED);
        } else {
            zuJian.withdrawstatus.setTextColor(Color.BLACK);
        }
        //提现成功的时候，才显示实际金额。
        if (WithdrawRecordsBill.STATUS_WD_SUCCESS == wdStatus) {
            zuJian.ll_actualWithdrawAmount.setVisibility(View.VISIBLE);
        } else {
            zuJian.ll_actualWithdrawAmount.setVisibility(View.GONE);
        }
		zuJian.applyWithdrawAmount.setText(CommonUtils.formatMoney(bills.getApplyWithdrawAmount()/100));
		zuJian.actualWithdrawAmount.setText(CommonUtils.formatMoney(bills.getActualWithdrawAmount()/100));
		return convertView;
	}	
	public final class ZuJian { 
	    private TextView withdrawapplytime = null; 
	    private TextView withdrawstatus = null; 
	    private LinearLayout ll_applyWithdrawAmount;
	    private LinearLayout ll_actualWithdrawAmount;
	    private TextView applyWithdrawAmount = null;
	    private TextView actualWithdrawAmount = null;
	}

}
